Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

214
Vistas
How to override (disable) the "submit" behaviour of a button tag inside of a form tag?
<form action="">
  <button>click</button>
</form>

The default behaviour of a button inside a form is to submit that form.

How can I disable the submit behaviour of that button?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Add a type="button" to it:

<button type="button">Click</button>

The types availabe are:

  • "submit": Default value. Submits the form.
  • "reset": Resets the form's inputs.
  • "button": Does nothing.

A good reference: https://developer.mozilla.org/en/DOM/HTMLButtonElement

over 4 years ago · Santiago Trujillo Denunciar

0

This will disable via javascript

<button onclick='return false'>click</button>

But you can just define the type

<button type='button'>click</button>
over 4 years ago · Santiago Trujillo Denunciar

0

There are occasions where you want to keep the niceties of a submit button (for instance, on a mobile device, where the submit button can be triggered from the keyboard, but only if the button is part of the form and of type submit). In this case what you need to do is prevent the default action of the button.

Using jQuery 1.7+ (using .on - I highly recommend reading the documentation - there are many nuances to using .on that can vastly affect performance)

$(document).on("click", "button", "event", function(evt) {
    evt.preventDefault();
    ...
}

Using older versions of jQuery...

$("#button-id").bind("click", function(evt, ui) {
    evt.preventDefault();
    ...
}

Note that you can use any selector (select by class, element type etc) or an method of binding to the event (instead of .bind, use .live, .delegate as appropriate to your version of jquery.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda